import {
	pageShare
} from '@/mixins/pageShare';
import {
	pagingMixin
} from '@/mixins/pagingMixin';
export const comSearch = {
	mixins: [pagingMixin, pageShare],
	data() {
		return {
			tabList: [],
			parameter: {},
			loadNext: true, // 是否加载下级分类
		}
	},
	onLoad: function(options) {
		uni.setNavigationBarTitle({
			title: options.title || this.title
		});
		if (options && options.id) {
			this.currentClass = Number(options.id);
			this.parentClass = Number(options.id);
		}
		if (options && options.loadNext) {
			this.loadNext = options.loadNext == 1 ? true : false
		}
		this.filterParameter(options)
		this.loadTabList()
		this.$initPage();
	},
	onShareAppMessage: function() {
		return this.getShareAppMessage();
	},
	onShareTimeline: function() {
		return this.getShareTimeline();
	},
	onReachBottom() {
		this._load_data();
	},
	methods: {
		filterParameter() {},
		$initPage() {
			let name = this.$refs.search_view.searchInput || ''
			let params = {
				name: name,
				...this.parameter
			};
			if (this.classType) {
				params[this.searchClasskey] = this.currentClass
			}
			this._init_data(this.listApi, params);
		},
		// 加载分类
		loadTabList() {
			if (!this.classType || !this.loadNext) {
				return
			}
			this.$resPost('GetCommonClassify', {
				parent_id: this.parentClass,
				type: this.classType,
				page_size: 200
			}).then(({
				data
			}) => {
				if (data[0]) {
					this.tabList = [{
						name: '全部',
						pk_id: this.parentClass
					}].concat(data);
				}
			});
		},
		searchConfirm() {
			this.$initPage()
		}
	}
}
